#include "roundpage.h"
#include<QPainter>
#include<QPixmap>
#include<QPen>
#include<QBrush>
#include"mydata.h"
RoundPage::RoundPage(QWidget *parent) : QWidget(parent)
{

}

void RoundPage::paintEvent(QPaintEvent *)
{
    QPainter painter;
    QPixmap pix(":/Image/RoadMap.jpg");
    QBrush brush;
    brush.setStyle(Qt::SolidPattern);
    QPen pen;

    painter.begin(&pix);

    for(int i=0; i<MyData::getObject()->junctionCount(); i++)
    {
        for(int j = 0;j<MyData::getObject()->getJunction(i)->lampCount();j++)
        {
            SignalLamp *lamp = MyData::getObject()->getJunction(i)->getLamp(j);
            int roundIndex = lamp->roundIndex;
            QColor color = lamp->color;
            brush.setColor(color);
            pen.setColor(color);
            painter.setBrush(brush);
            painter.setPen(pen);
            Round *r =MyData::getObject()->getRound(roundIndex);
            int x,y,w,h;
            if(r->dir == 0)
            {
                //up
                w=33;
                h=5;
                x=r->x - 15;
                y=r->y - 6;
            }
            else if (r->dir == 1) {
                //down
                w=33;
                h=5;
                x=r->x - 15;
                y=r->y + r->h +1;
            }
            else if (r->dir ==2) {
                //left
                w= 5;
                h= 33;
                x=r->x- 6;
                y=r->y- 15;
            }
            else {
                //right
                w=5;
                h=33;
                x=r->x+r->w+1;
                y=r->y-15;
            }
            painter.drawRect(x,y,w,h);
        }
    }

    painter.end();

    painter.begin(this);

    painter.drawPixmap(0,0,width(),height(),pix);
    painter.end();
}
